/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.editparts;

import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editpolicies.DirectEditPolicy;

import edu.pku.sei.modeler.editpolicies.UMLDiagramGraphicalNodeEditPolicy;
import edu.pku.sei.modeler.figures.MergeNodeFigure;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.structure.MetaShapeElement;
import edu.pku.sei.modeler.model.uml.IntermediateActivities.MergeNode;

/**
 * @generated
 * 
 */
public class MergeNodeEditpart extends AbstractUMLNodeEditPart {
	public MergeNodeEditpart(MetaShapeElement model) {
		super(model);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
	 */
	protected IFigure createFigure() {
		Label header = new Label("GeneratedShape");
		MergeNodeFigure figure = new MergeNodeFigure();
		figure.add(header);
		return figure;
	}

	protected DirectEditPolicy createDirectEditPolicy() {
		// return new DirectEditPolicy(){
		//
		// @Override
		// protected Command getDirectEditCommand(DirectEditRequest arg0) {
		// return new ChangeNameCommand(getMergeNode(),
		// (String)arg0.getCellEditor().getValue());
		// }
		//
		// @Override
		// protected void showCurrentEditValue(DirectEditRequest arg0) {
		// IFigure f = getDirectEditFigure();
		// if (f instanceof Label) {
		// ((Label)f).setText(getMergeNode().getName());
		// }
		// }
		//			
		// };
		return null;
	}

	@Override
	protected IFigure getDirectEditFigure() {
		// return ((MergeNodeFigure)this.getFigure()).getMergeLable();
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
	 */
	protected void createEditPolicies() {
		super.createEditPolicies();
	}

	protected void handlePropertyChanged(PropertyChangeEvent event) {
		String propertyName = event.getPropertyName();
		super.handlePropertyChanged(event);
		refreshVisuals();
	}

	private MergeNode getMergeNode() {
		return (MergeNode) ((MetaNode) getModel()).getModelElement();
	}

	protected void refreshVisuals() {
		super.refreshVisuals();
		MergeNode modelEle = (MergeNode) getNode().getModelElement();
		MergeNodeFigure figure = (MergeNodeFigure) getFigure();

		figure.getMergeLable().setText("" + modelEle.getName());

	}
}
